<?php

/**
 * Show employee information function
 *
 * Return employee profile information
 *
 * @author Dawid Marciniak <dawidm@gmail.com>
 */
include_once 'UTerrorcode.php';
include_once 'UTcheckAuth.php';
include_once 'UTDBGlobal.php';

/**
 * @param $userName string
 * @param $userPass string
 * @param $targetUser string
 * @return array|void
 */
function checkIfManager($userName, $userPass) {
    global $dbaddress;
    global $dbuser;
    global $dbpassword;
    global $dbdatabasename;

    //declare output and auth success/fail var, error code generated throughout
    $output = array();
    $auth = 0;
    $error = 0;
    $isManager = false;

    if (checkAuthentication($userName, $userPass) == true) {
        $conn = mysqli_connect($dbaddress, $dbuser, $dbpassword, $dbdatabasename);
        //check if user is manager
        $sql = "SELECT empStatus FROM employees as e, account as a WHERE e.empID = a.empID AND a.accName = '$userName'";
        $result = mysqli_query($conn, $sql);
        $row = mysqli_fetch_object($result);
        if ($row == NULL) {
            $error = 300 + ErrorCode::failRead;
        } else {
            $empStatus = $row->empStatus;
            $isManager = $empStatus == 'Manager';
            $error = ErrorCode::successRead;
        }
    } else {
        $error = ErrorCode::authFailRead;
    }

    $output = array(
        'code' => $error,
        'isManager' => $isManager
    );
    return $output;
}